package com.xu.CAS;

import java.util.concurrent.atomic.AtomicInteger;

/**
 *
 * @author xudenghui
 * @create 2023-02-27 11:46
 **/
public class CASDemo1 {
    public static void main(String[] args) {
        test1();
    }

    /**
     *
     */
    public static  void test1(){
        AtomicInteger atomicInteger = new AtomicInteger(6);
        //第一次C的值等于A 故将C改为B，第二次C的值不等于A 故不修改
        System.out.println(atomicInteger.compareAndSet(6,2022)+"\t"+ atomicInteger.get());
        System.out.println(atomicInteger.compareAndSet(6,2022)+"\t"+ atomicInteger.get());
    }
}
